package com.example.demo.utils.convert;

/**
 * @description: 换算转换（long 数转化为KB、MB、GB）
 * @author: cj
 * @create: 17-03-08 17:03:42
 */
public class ConvertUtil {
    public static String getPrintSize(long size) {
        long rest = 0;
        if(size < 1024){
            return String.valueOf(size) + "B";
        }else{
            size /= 1024;
        }

        if(size < 1024){
            return String.valueOf(size) + "KB";
        }else{
            rest = size % 1024;
            size /= 1024;
        }

        if(size < 1024){
            size = size * 100;
            return String.valueOf((size / 100)) + "." + String.valueOf((rest * 100 / 1024 % 100)) + "MB";
        }else{
            size = size * 100 / 1024;
            return String.valueOf((size / 100)) + "." + String.valueOf((size % 100)) + "GB";
        }
    }


}
